<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="id">
                <el-input
                    v-model="queryParams.id"
                    placeholder="请输入id"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="退款表ID">
                <el-input
                    v-model="queryParams.refund_id"
                    placeholder="请输入退款表ID"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="用户ID">
                <el-input
                    v-model="queryParams.userid"
                    placeholder="请输入用户ID"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="充值订单ID">
                <el-input
                    v-model="queryParams.deposit_id"
                    placeholder="请输入充值订单ID"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="退款金额">
                <el-input
                    v-model="queryParams.price"
                    placeholder="请输入退款金额"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="创建时间">
                <el-date-picker
                    v-model="queryParams.create_time"
                    type="date"
                    value-format="YYYY-MM-DD"
                    placeholder="请选择创建时间"
                />
            </el-form-item>
            <el-form-item label="&nbsp;">
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                    type="warning"
                    plain
                    icon="Download"
                    @click="handleExport"
                >导出
                </el-button>
            </el-col>
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="ID" align="center" prop="id"/>
            <el-table-column label="退款表ID" align="center" prop="refund_id" />
            <el-table-column label="用户ID" align="center" prop="userid" />
            <el-table-column label="充值订单ID" align="center" prop="deposit_id" />
            <el-table-column label="退款金额" align="center" prop="price" :formatter="(row) => {return '￥' + row.price}"/>
            <el-table-column label="创建时间" align="center" prop="create_time" width="180">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.create_time) }}</span>
                </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    </div>
</template>

<script>
import * as api from "@/api/finance/recharge";
export default {
    name: 'RefundDetail',
    components: {  },
    props: {
      recharge_id: {
        type: Number,
        required: true
      },
    },
    data() {
      return {
        list:[],
        loading:true,
        showSearch:false,
        total:0,
        queryParams: {
          pageNum: 1,
          pageSize: 10,
        },
        form: {},
        rules: {},
      };
    },
    mounted(){
      this.queryParams.userid = this.recharge_id
      this.getList()
    },
    methods: {
      getList() {
        this.loading = true;
        api.listRecharge(this.queryParams).then(response => {
            this.list = response.rows || [];
            this.total = response.total || 0;
            this.loading = false;
        });
      },
      handleQuery() {/** 搜索按钮操作 */
        this.queryParams.pageNum = 1;
        this.getList();
      },
      resetQuery() {/** 重置按钮操作 */
        this.dateRange = [];
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
        };
        this.resetForm("queryRef");
        this.handleQuery();
      },
      handleExport() {/** 导出按钮操作 */
        this.download(api.EXPORT_URL, {
            ...this.queryParams
        }, `recharge_${new Date().getTime()}.xlsx`);
      },
    }
  }
</script>
